Skip to content

Conversation

a2they
Copy link

@a2they a2they commented Sep 20, 2024

Replacing Bundle.module with Bundle(for: self) to accommodate building transformers outside SPM context.

Copy link
Member

@pcuenca pcuenca left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very cool, thanks for showing how to do it! 🔥

Apologies for the delay in reviewing, it was a 🦙 week.

I'll check what's happening with the CI.

@@ -202,7 +202,8 @@ public class LanguageModelConfigurationFromHub {
}

static func fallbackTokenizerConfig(for modelType: String) -> Config? {
guard let url = Bundle.module.url(forResource: "\(modelType)_tokenizer_config", withExtension: "json") else { return nil }
let bundle = Bundle(for: self)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could fix the tests doing something like:

Suggested change
let bundle = Bundle(for: self)
let bundle = NSClassFromString("XCTest") != nil ? Bundle.module : Bundle(for: self)

But upon additional testing I found that building a CLI that uses Tokenizers would not find the fallback configuration either.

Do you have any thoughts on that? Some additional ideas:

  • Iterate through the bundles and select the right one.
  • Create a bundle (or framework?) solely dedicated to hosting the resources.
  • Download the fallback configs from a well-known location in the Hub.

@pcuenca
Copy link
Member

pcuenca commented Aug 19, 2025

This turned out trickier than expected, closing for now.

@pcuenca pcuenca closed this Aug 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants